package com.geeksaga.web;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

/**
 * @author newbie
 * @since 0.1
 */
@Controller
public class LocaleController {
	public static final String KOREA_LOCALE = "ko";
	public static final String ENGLISH_LOCALE = "en";

	@RequestMapping(value = { "/changeLocale.do" })
	public String changeLocale(@RequestParam(required = false) String locale, HttpServletRequest request,
			HttpServletResponse response) {
	    
		Locale LOCALE = null;

		if (KOREA_LOCALE.equals(locale))
		    LOCALE = Locale.KOREAN;
		else if (ENGLISH_LOCALE.equals(locale))
		    LOCALE = Locale.ENGLISH;
		else
		    LOCALE = Locale.KOREAN;

		HttpSession session = request.getSession();
		session.setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, LOCALE);
		
		return "index";
	}
}